home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / gcc / gcc261c.zoo / objects / IndexedCollecting.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-18  |  7.4 KB  |  204 lines

  1. /* Protocol for Objective-C objects that hold elements accessible by index
  2.    Copyright (C) 1993,1994 Free Software Foundation, Inc.
  3.  
  4.    Written by:  R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
  5.    Date: May 1993
  6.  
  7.    This file is part of the GNU Objective C Class Library.
  8.  
  9.    This library is free software; you can redistribute it and/or
  10.    modify it under the terms of the GNU Library General Public
  11.    License as published by the Free Software Foundation; either
  12.    version 2 of the License, or (at your option) any later version.
  13.    
  14.    This library is distributed in the hope that it will be useful,
  15.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  17.    Library General Public License for more details.
  18.  
  19.    You should have received a copy of the GNU Library General Public
  20.    License along with this library; if not, write to the Free
  21.    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22. */ 
  23.  
  24. /* The <IndexedCollecting> protocol inherits from the 
  25.    <KeyedCollecting> protocol.
  26.  
  27.    The <IndexedCollecting> protocol defines the interface to a
  28.    collection of elements that are accessible by a key that is an index,
  29.    where the indeces in a collection are a contiguous series of unsigned
  30.    integers beginning at 0.  This is the root of the protocol heirarchy
  31.    for all collections that hold their elements in some order.  Elements
  32.    may be accessed, inserted, replaced and removed by their index.  
  33. */
  34.  
  35. #ifndef __IndexedCollecting_h_OBJECTS_INCLUDE
  36. #define __IndexedCollecting_h_OBJECTS_INCLUDE
  37.  
  38. #include <objects/stdobjects.h>
  39. #include <objects/KeyedCollecting.h>
  40.  
  41. typedef struct _IndexRange { 
  42.   unsigned start;
  43.   unsigned end;
  44. } IndexRange;
  45. /* Includes elements from start to end-1  Is this ugly?
  46.    I do this so I can specify a NULL range 
  47.    How about this instead:
  48.    typedef struct _IndexRange {
  49.      unsigned start;
  50.      unsigned length;
  51.    }
  52. */
  53.  
  54. //#define MakeIndexRange(START,END) \
  55. //  ({ IndexRange __ir = {(START), (END)}; __ir; })
  56. // USE:  ((IndexRange) {(START),(END)})
  57.  
  58. #define IndexRangeInside(RANGE1,RANGE2) \
  59.   ({IndexRange __a=(RANGE1), __b=(RANGE2); \
  60.     __a.start<=__b.start && __a.end>=__b.end;})
  61.  
  62.  
  63. @protocol IndexedCollecting <KeyedCollecting>
  64.  
  65. // ADDING;
  66. - insertObject: newObject atIndex: (unsigned)index;
  67. - insertObject: newObject before: oldObject;
  68. - insertObject: newObject after: oldObject;
  69. - insertContentsOf: (id <Collecting>)aCollection atIndex: (unsigned)index;
  70. - appendObject: newObject;
  71. - prependObject: newObject;
  72. - appendContentsOf: (id <Collecting>)aCollection;
  73. - prependContentsOf: (id <Collecting>)aCollection;
  74.  
  75. // REPLACING AND SWAPPING
  76. - replaceObjectAtIndex: (unsigned)index with: newObject;
  77. - replaceRange: (IndexRange)aRange with: (id <Collecting>)aCollection;
  78. - replaceRange: (IndexRange)aRange using: (id <Collecting>)aCollection;
  79. - swapAtIndeces: (unsigned)index1 : (unsigned)index2;
  80.  
  81. // REMOVING
  82. - removeObjectAtIndex: (unsigned)index;
  83. - removeFirstObject;
  84. - removeLastObject;
  85. - removeRange: (IndexRange)aRange;
  86.  
  87. // GETTING MEMBERS BY INDEX;
  88. - objectAtIndex: (unsigned)index;
  89. - firstObject;
  90. - lastObject;
  91.  
  92. // GETTING MEMBERS BY NEIGHBOR;
  93. - successorOfObject: anObject;
  94. - predecessorOfObject: anObject;
  95.  
  96. // GETTING INDICES BY MEMBER;
  97. - (unsigned) indexOfObject: anObject;
  98. - (unsigned) indexOfObject: anObject 
  99.     ifAbsentCall: (unsigned(*)(arglist_t))excFunc;
  100. - (unsigned) indexOfObject: anObject inRange: (IndexRange)aRange;
  101. - (unsigned) indexOfObject: anObject inRange: (IndexRange)aRange
  102.     ifAbsentCall: (unsigned(*)(arglist_t))excFunc;
  103.  
  104. // TESTING;
  105. - (BOOL) includesIndex: (unsigned)index;
  106. - (BOOL) contentsEqualInOrder: (id <IndexedCollecting>)aColl;
  107. - (unsigned) indexOfFirstDifference: (id <IndexedCollecting>)aColl;
  108. - (unsigned) indexOfFirstIn: (id <Collecting>)aColl;
  109. - (unsigned) indexOfFirstNotIn: (id <Collecting>)aColl;
  110.  
  111. // ENUMERATING;
  112. - (BOOL) getPrevObject: (id*)anIdPtr withEnumState: (void**)enumState;
  113. - withObjectsInRange: (IndexRange)aRange call:(void(*)(id))aFunc;
  114. - withObjectsInReverseCall: (void(*)(id))aFunc;
  115. - withObjectsInReverseCall: (void(*)(id))aFunc whileTrue:(BOOL *)flag;
  116.  
  117. // ENUMERATING WHILE CHANGING CONTENTS;
  118. - safeWithObjectsInReverseCall: (void(*)(id))aFunc;
  119. - safeWithObjectsInReverseCall: (void(*)(id))aFunc whileTrue:(BOOL *)flag;
  120.  
  121. // SORTING;
  122. - sortContents;
  123. - sortObjectsByCalling: (int(*)(id,id))aFunc;
  124. - sortAddObject: newObject;
  125. - sortAddObject: newObject byCalling: (int(*)(id,id))aFunc;
  126.  
  127.  
  128. // NON-OBJECT MESSAGE NAMES;
  129.  
  130. // ADDING;
  131. - appendElement: (elt)newElement;
  132. - prependElement: (elt)newElement;
  133. - insertElement: (elt)newElement atIndex: (unsigned)index;
  134. - insertElement: (elt)newElement before: (elt)oldElement;
  135. - insertElement: (elt)newElement after: (elt)oldElement;
  136.  
  137. // REMOVING AND REPLACING;
  138. - (elt) removeElementAtIndex: (unsigned)index;
  139. - (elt) removeFirstElement;
  140. - (elt) removeLastElement;
  141. - (elt) replaceElementAtIndex: (unsigned)index with: (elt)newElement;
  142.  
  143. // GETTING ELEMENTS BY INDEX;
  144. - (elt) elementAtIndex: (unsigned)index;
  145. - (elt) firstElement;
  146. - (elt) lastElement;
  147.  
  148. // GETTING MEMBERS BY NEIGHBOR;
  149. - (elt) successorOfElement: (elt)anElement;
  150. - (elt) predecessorOfElement: (elt)anElement;
  151.  
  152. // GETTING INDICES BY MEMBER;
  153. - (unsigned) indexOfElement: (elt)anElement;
  154. - (unsigned) indexOfElement: (elt)anElement
  155.     ifAbsentCall: (unsigned(*)(arglist_t))excFunc;
  156. - (unsigned) indexOfElement: (elt)anElement inRange: (IndexRange)aRange;
  157. - (unsigned) indexOfElement: (elt)anElement inRange: (IndexRange)aRange
  158.     ifAbsentCall: (unsigned(*)(arglist_t))excFunc;
  159.  
  160. // ENUMERATING;
  161. - (BOOL) getPrevElement:(elt*)anElementPtr withEnumState: (void**)enumState;
  162. - withElementsInRange: (IndexRange)aRange call:(void(*)(elt))aFunc;
  163. - withElementsInReverseCall: (void(*)(elt))aFunc;
  164. - withElementsInReverseCall: (void(*)(elt))aFunc whileTrue:(BOOL *)flag;
  165.  
  166. // ENUMERATING WHILE CHANGING CONTENTS;
  167. - safeWithElementsInRange: (IndexRange)aRange call:(void(*)(elt))aFunc;
  168. - safeWithElementsInReverseCall: (void(*)(elt))aFunc;
  169. - safeWithElementsInReverseCall: (void(*)(elt))aFunc whileTrue:(BOOL *)flag;
  170.  
  171. // SORTING;
  172. - sortElementsByCalling: (int(*)(elt,elt))aFunc;
  173. - sortAddElement: (elt)newElement;
  174. - sortAddElement: (elt)newElement byCalling: (int(*)(elt,elt))aFunc;
  175.  
  176. @end
  177.  
  178. /* Most methods in the KeyedCollecting protocol that mention a key are
  179.    duplicated in the IndexedCollecting protocol, with their names 
  180.    modified to reflect that the "key" now must be an unsigned integer, 
  181.    (an "index").  The programmer should be able to use either of the 
  182.    corresponding method names to the same effect.
  183.  
  184.    The new methods are provided in the IndexedCollecting protocol for:
  185.       1) Better type checking for when an unsigned int is required.
  186.       2) More intuitive method names.
  187.  
  188.    IndexedCollecting                        KeyedCollecting
  189.    ----------------------------------------------------------------------
  190.    insertObject:atIndex                     insertObject:atKey:
  191.    replaceObjectAtIndex:with:               replaceObjectAtKey:with:
  192.    removeObjectAtIndex:                     removeObjectAtKey:
  193.    objectAtIndex:                           objectAtKey:
  194.    includesIndex:                           includesKey:
  195.  
  196.    insertElement:atIndex                    insertElement:atKey:
  197.    replaceElementAtIndex:with:              replaceElementAtKey:with:
  198.    removeElementAtIndex:                    removeElementAtKey:
  199.    elementAtIndex:                          elementAtKey:
  200.  
  201. */
  202.  
  203. #endif /* __IndexedCollecting_h_OBJECTS_INCLUDE */
  204.